{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ART BlackBox Classifier - Creating adversarial samples for remote classifiers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This demo consists of two parts. The first part deploys a trained model using IBM Watson Machine Learning service to create an API. The second connects to this endpoint and attacks the deployed model with the HopSkipJump attack using only the model predictions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from __future__ import absolute_import, division, print_function, unicode_literals\n",
    "\n",
    "import numpy as np\n",
    "from IPython.display import clear_output\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "from art import config\n",
    "from art.estimators.classification import BlackBoxClassifier\n",
    "from art.attacks.evasion import HopSkipJump\n",
    "from art.utils import to_categorical\n",
    "from art.utils import load_dataset, get_file, compute_accuracy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Deploy model and connect to API"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To deploy a model and connect to the endpoint for model predictions, please follow the demo:\n",
    "[Use TensorFlow to predict handwritten digits](https://dataplatform.cloud.ibm.com/analytics/notebooks/v2/3bd3efb8-833d-460f-b07b-fee51dd0f1af/view?access_token=6bd0ff8d807861d09e0dab0cad28ce9685711078f612fcd92bb8cf8535d089c1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# generate wml client object following the tutorial above (part 1)\n",
    "client = 'TODO'\n",
    "\n",
    "# generate api endpoint following the tutorial above (part 6)\n",
    "scoring_url = 'TODO'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Make predictions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We show an example of a predict function below that connects to a wml endpoint and returns the predictions of the deployed model. A different function could be written for another remote classifier that outputs predictions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Read MNIST dataset\n",
    "(x_train, y_train), (x_test, y_test), min_, max_ = load_dataset(str('mnist'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Sample predict function that reformats inputs, connects to wml scoring endpoint and \n",
    "# returns one-hot encoded predictions\n",
    "def predict(x):\n",
    "    x = np.array(x)\n",
    "    scoring_data = {'values': (np.reshape(x, (x.shape[0],784))).tolist()}\n",
    "    predictions = client.deployments.score(scoring_url, scoring_data)\n",
    "    return to_categorical(predictions['values'], nb_classes=10)\n",
    "    \n",
    "# Create blackbox object\n",
    "classifier = BlackBoxClassifier(predict, x_train[0].shape, 10, clip_values=(0, 255))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAADoBJREFUeJzt3X2MXOV1x/HfyXq9jo1JvHHYboiLHeMEiGlMOjIgLKCiuA5CMiiKiRVFDiFxmuCktK4EdavGrWjlVgmRQynS0ri2I95CAsJ/0CR0FUGiwpbFMeYtvJlNY7PsYjZgQ4i9Xp/+sdfRBnaeWc/cmTu75/uRVjtzz71zj6792zszz8x9zN0FIJ53Fd0AgGIQfiAowg8ERfiBoAg/EBThB4Ii/EBQhB8IivADQU1r5M6mW5vP0KxG7hII5bd6U4f9kE1k3ZrCb2YrJG2W1CLpP9x9U2r9GZqls+2iWnYJIKHHuye8btVP+82sRdJNkj4h6QxJq83sjGofD0Bj1fKaf6mk5919j7sflnSHpJX5tAWg3mo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pt9eODYJKnZ78GC+/mdZpq5ebyZpdUEx66ZZrwuIvyPSFpkZgvMbLqkT0vaUUAf72Bms7I3YmRmsyQtV/PNPrxD0prs9hpJ9xbYy+9plpmby80srYKPXdPNeO3uDf+RdIlG3/F/QdLfFtFDmb4+JOmx7OfJonuTdLtGnwYOa/S9kaskvU9St6TnJP23pPYm6u27kh6XtFujQessqLdlGn1Kv1vSruznkqKPXaKvQo4bn/ADguINPyAowg8ERfiBoAg/EBThB4Ii/EBQhB8IivADQf0/sEWOix6VKakAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1829ec52e8>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prediction from API is: 5\n"
     ]
    }
   ],
   "source": [
    "# Select target image and show prediction\n",
    "target_image = x_train[0]\n",
    "plt.imshow(np.reshape(target_image.astype(np.float32), (28, 28)))\n",
    "plt.show(block=False)\n",
    "print('Prediction from API is: ' + str(np.argmax(classifier.predict(x_train[:1]), axis=1)[0]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Generate black box HopSkipJump attack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adversarial image at step 0. L2 error 7.9944905692156425 and class label 3.\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAG0xJREFUeJztnXuU3OV537/PzM7e77va1ep+x8iAJLJggwkGbMyl2FxObMc+SXCaRqkbn2M3Pj117TRx2ibHp63jk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O5SJhZD4Budy95TNjMrgUwAuB+d78kf99/BjDg7l/Lv3G2uPu/LZO5fRXASKk7N+cbynTN7CwN4A4An0EJjx2Z1ydQguNWiiv/lQAOuvthd58C8BCA20swj7LH3Z8F8M6qELcDuC9/+z5MnzxFJzC3ssDdT7j7S/nbwwDe6ixd0mNH5lUSSmH+xQDenPH3UZRXy28H8JSZvWhmm0s9mXPQmW+bDgC9ADpLOZlzULBzczF5R2fpsjl2c+l4fb7RD34/yTXufjmAWwD8Zv7jbVni09/ZyilcM6vOzcXiHJ2lf0wpj91cO16fb0ph/mMAZja+W5K/ryxw92P5//sBPILy6z7c91aT1Pz//SWez48pp87N5+osjTI4duXU8boU5t8OYK2ZrTSzSgC/COCxEszjJzCzuvwPMTCzOgAfQfl1H34MwN3523cDeLSEc3kb5dK5OdRZGiU+dmXX8drdi/4PwK2Y/sX/EICvlGIOgXmtArAr/29vqecG4EFMfwxMY/q3kV8D0AZgK4ADAP4BQGsZze2vALwCYDemjdZVorldg+mP9LsB7Mz/u7XUx47MqyTHTSv8hIgU/eAnRKTI/EJEiswvRKTI/EJEiswvRKTI/EJEiswvRKTI/EJEyv8D+uU/YB2cHMwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1825477748>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adversarial image at step 10. L2 error 1.4959683890579352 and class label 3.\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAGJ9JREFUeJztnXuQnGWVxp/zdc8kk8sMuZmEEJJwE4Eto44RFVfX2yL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03s6vasYYUZjZgZg+Z2QNmtqbNa7nBzHaZ2cOjbptpZnea2WON/0/YJq1Na7vGzLY2zt0DZnZJm9a20Mz+x8x+Y2aPmNmHGre39dyRdbXlvLX8z34zqwBYB+B1ALYAuBfApe7+m5YuJIGZDQDod/e2x4TN7E8BHAHwDXe/oHHbpwDsc/drG2+cM9z9Ix2ytmsAHGl35+ZGQ5n5oztLA3gLgPeijeeOrOsdaMN5a8eVfxmA9e6+wd2HAHwHwPI2rKPjcfe7Afx+1YnlAG5s/HwjRl48LSexto7A3be7+/2Nnw8DeKqzdFvPHVlXW2iH+RcAGF02Zws6q+W3A7jDzO4zsxXtXswJmNtomw4AOwDwtjetJ+zc3Ep+r7N0x5y7sXS8nmj0hd8fcpG7vxDAGwBc0fjztiPxkc9snRSuaapzc6s4QWfp39HOczfWjtcTTTvMvxXAwlG/n9a4rSNw962N/3cBuBWd131451NNUhv/72rzen5HJ3VuPlFnaXTAueukjtftMP+9AM42syVm1g3gnQBua8M6/gAzm9r4IgZmNhXA69F53YdvA3BZ4+fLAKxq41qeRqd0bk51lkabz13Hdbx295b/A3AJRr7xfxzA37djDYl1nQHg141/j7R7bQC+jZE/A4cx8t3I+wDMAnAXgMcA/DeAmR20tm8CeAjAgxgx2vw2re0ijPxJ/yCABxr/Lmn3uSPrast50w4/ITJFX/gJkSkyvxCZIvMLkSkyvxCZIvMLkSkyvxCZIvMLkSkyvxCZ8v8IhkdHutqS4QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1829f85b70>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Adversarial image at step 20. L2 error 1.0073771113688348 and class label 3.\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAAD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e1YBxtz93vB7D3qJsvA7Cu9vE6TDx5mi4xtrbg7rvc/ee1j/cDeLmzdEuvHRlXS7Qi+ZcB2D7p8x1or5bfDuBeM3vIzFa1ejBTWFJrmw4AzwMIWs80Xdi5uZmO6izdNtduOh2vZ5re8Hu1C9z9HADvAfDx2q+3bckn/mZrp3JNXZ2bm2WKztK/1sprN92O1zOtFck/CGDyJmUn125rC+4+WPt/CMB30H7dh3e/3CS19j9vGtdE7dS5earO0miDa9dOHa9bkfwPAlhpZqeYWReADwDY0IJxvIqZza+9EQMzmw/g3Wi/7sMbAFxT+/gaAHe3cCyv0C6dm1OdpdHia9d2Ha/dven/AFyCiXf8fwXg860YQ2JcpwL4v9q/x1s9NgB3YOLXwHFMvDfyYQD9ADYC+CWAHwDoa6OxfQ3AZgCPYiLRlrZobBdg4lf6RwE8Uvt3SauvHRlXS66bZviJZEpv+IlkSskvkiklv0imlPwimVLyi2RKyS+SKSW/SKaU/CKZ+n+udwH92s1wTgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1851838b70>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Generate HopSkipJump attack against black box classifier\n",
    "attack = HopSkipJump(classifier=classifier, targeted=False, max_iter=0, max_eval=1000, init_eval=10)\n",
    "iter_step = 10\n",
    "x_adv = None\n",
    "for i in range(3):\n",
    "    x_adv = attack.generate(x=np.array([target_image]), x_adv_init=x_adv)\n",
    "    \n",
    "    print(\"Adversarial image at step %d.\" % (i * iter_step), \"L2 error\", \n",
    "          np.linalg.norm(np.reshape(x_adv[0] - target_image, [-1])),\n",
    "          \"and class label %d.\" % np.argmax(classifier.predict(x_adv)[0]))\n",
    "    plt.imshow(np.reshape(x_adv[0].astype(np.float32), (28, 28)))\n",
    "    plt.show(block=False)\n",
    "    \n",
    "    attack.max_iter = iter_step"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
